package jeons.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import jeons.Basket.dto.BasketDTO;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartHttpServletRequest;



@Service
public class Utils {
	
	/**
	* @Method Name  : MultipartFiles
	* @占쌜쇽옙占쏙옙   : 2012. 1. 16.
	* @占쌜쇽옙占쏙옙   : user
	* @占쏙옙占쏙옙占싱뤄옙  :
	* @Method 占쏙옙占쏙옙 : 占쏙옙청 占쏙옙占쏙옙 처占쏙옙
	* @param request
	* @param name
	* @return
	*/
	@SuppressWarnings("rawtypes")
	public static List MultipartFiles(HttpServletRequest request, String name)
	    {
	        MultipartHttpServletRequest multipart = (MultipartHttpServletRequest)request;
	        return multipart.getFiles(name);
	    }
	
	/**
	* @Method Name  : getYmdhhmmss
	* @占쌜쇽옙占쏙옙   : 2012. 1. 31.
	* @占쌜쇽옙占쏙옙   : user
	* @占쏙옙占쏙옙占싱뤄옙  : 날짜 패턴
	* @Method 占쏙옙占쏙옙 :
	* @param pattern
	* @return
	*/
	public static String getYmdhhmmss(String pattern){
		SimpleDateFormat dateFormat = new SimpleDateFormat();
		dateFormat.applyPattern(pattern);
		return dateFormat.format(new Date());
	}
	
	/**
	* @Method Name  : formatDate
	* @작성일   : 2012. 2. 23.
	* @작성자   : user
	* @변경이력  :
	* @Method 설명 : 날짜 데이트 패턴
	* @param patten
	* @return
	* @throws ParseException
	*/
	public static Date formatDate(String patten) throws ParseException{
		SimpleDateFormat sf = new SimpleDateFormat(patten);
		return sf.parse(sf.format(new Date()));
	}
	
	/**
	* @Method Name  : formDataString
	* @작성일   : 2012. 2. 23.
	* @작성자   : user
	* @변경이력  :
	* @Method 설명 : 날짜 패턴 스트링으로 반환
	* @param usrdate
	* @return
	*/
	public static String formDataString(Date usrdate){
		SimpleDateFormat dateFormat = new SimpleDateFormat();
		dateFormat.applyPattern("yyyy-MM-dd HH:mm:ss");
		return dateFormat.format(usrdate);
	}
	
	/**
	* @Method Name  : getU_id
	* @작성일   : 2012. 2. 23.
	* @작성자   : user
	* @변경이력  :
	* @Method 설명 :
	* @param request
	* @return
	*/
	public static String getU_id(HttpServletRequest request){
		HttpSession session = (HttpSession) request.getAttribute("u_id");;
		String u_id = (String) session.getAttribute("u_id");
		return u_id;
	}
	
	/**
	* @Method Name  : creatArray
	* @占쌜쇽옙占쏙옙   : 2012. 2. 1.
	* @占쌜쇽옙占쏙옙   : user
	* @占쏙옙占쏙옙占싱뤄옙  :
	* @Method 占쏙옙占쏙옙 : 占쏙옙품 占썼열占쏙옙 占쏙옙占쏙옙
	* @param basketDTO
	* @return
	*/
	public static int[]  creatArray(BasketDTO basketDTO){
        int[] tmp = {basketDTO.getCpu(),basketDTO.getMemory(),basketDTO.getSnl(),basketDTO.getGraphic(),basketDTO.getHard(),basketDTO.getCd(),basketDTO.getB_power(),basketDTO.getB_case(),basketDTO.getMainboard(),basketDTO.getU_os(),basketDTO.getU_lcd(),basketDTO.getU_knm(),basketDTO.getU_spk()};
        return tmp;
    }
	
	
	public static String dateDay(Date dateD){
		Date date = dateD;
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int day = calendar.get(Calendar.DAY_OF_WEEK);
		switch(day)
		{
		case 1:
			return "일요일입니다.";
		case 2:
			return "월요일입니다.";
		case 3:
			return "화요일입니다.";
		case 4:
			return "수요일입니다.";
		case 5:
			return "목요일입니다.";
		case 6:
			return "금요일입니다.";
		case 7:
			return "토요일입니다.";
		}
		return "알아수없는 데이터입니다.";
	}
	
	
	
	
	
	
	public static String toDay(){
		
		Date date = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int day = calendar.get(Calendar.DAY_OF_WEEK);
		switch(day)
		{
		case 1:
			return "일요일입니다.";
		case 2:
			return "월요일입니다.";
		case 3:
			return "화요일입니다.";
		case 4:
			return "수요일입니다.";
		case 5:
			return "목요일입니다.";
		case 6:
			return "금요일입니다.";
		case 7:
			return "토요일입니다.";
		}
		return "알아수없는 데이터입니다.";
	}
	
}
